package iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.service.serviceConnection;

import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.IBinder;

import iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.service.ILoginService;
import iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.service.serviceImpl.LoginService;

public class LoginServiceConnection implements ServiceConnection {
    private LoginService loginService;
    private boolean mIsBound = false;

    public interface OnServiceConnectedCallback {
        void onServiceConnected(ILoginService service);
    }
    private final OnServiceConnectedCallback callback;
    public LoginServiceConnection(OnServiceConnectedCallback callback) {
        this.callback = callback;
    }

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        LoginService.LocalBinder binder = (LoginService.LocalBinder) service;
        loginService = binder.getService();
        mIsBound = true;

        if (callback != null) {
            callback.onServiceConnected(loginService);
        }
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
        mIsBound = false;
    }

    public ILoginService getService() {
        return loginService;
    }

    public boolean isBound() {
        return mIsBound;
    }
}